﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Com.AAS.Toolbox.DataMirror.Server
{
    class MonitorEvent : EventArgs
    {
        public EventType EventType { get; set; }         // 事件类型
        public EventState EventState { get; set; }       // 事件状态
        public EntityData EntityData { get; set; }
        public LogData LogData { get; set; }

        public Boolean HasEntityData
        {
            get
            {
                return EntityData != null ? true : false;
            }
        }

        public Boolean HasLogData
        {
            get
            {
                return LogData != null ? true : false;
            }
        }

        public MonitorEvent()
        {

        }

        public MonitorEvent(LogData logData)
        {
            this.EventType = EventType.LOG_MESSAGE;
            this.EventState = EventState.READY;
            this.LogData = logData;
        }

        public override String ToString()
        {
            StringBuilder buff = new StringBuilder();
            buff.Append("MonitorEvent - [").Append(EventType).Append(" - ").Append(EventState).Append("]").Append("\t ");
            if (HasEntityData)
                buff.Append(EntityData.ToString());
            if (HasLogData)
                buff.Append(LogData.ToString());
            return buff.ToString();
        }
    }

    class EntityData
    {
        public EntityType EntityType { get; set; }      // 实体类型
        public String OriginalMonitorPath { get; set; }
        public String OriginalFullPath { get; set; }
        public String OriginalName { get; set; }
        public String OldOriginalFullPath { get; set; }
        public String OldOriginalName { get; set; }
        public String OriginalMD5Code { get; set; }

        public override String ToString()
        {
            StringBuilder buff = new StringBuilder();
            buff.Append("\t{").Append("\r\n");
            buff.Append("\t\t").Append("OriginalMonitorPath : ").Append(OriginalMonitorPath).Append("\r\n");
            buff.Append("\t\t").Append("OriginalName : ").Append(OriginalName).Append("\r\n");
            buff.Append("\t\t").Append("OriginalFullPath : ").Append(OriginalFullPath).Append("\r\n");
            buff.Append("\t\t").Append("OldOriginalName : ").Append(OldOriginalName).Append("\r\n");
            buff.Append("\t\t").Append("OldOriginalFullPath : ").Append(OldOriginalFullPath).Append("\r\n");
            buff.Append("\t}").Append("\r\n"); 
            return buff.ToString();
        }
    }

    class LogData
    {
        public LogLevel Level { get; set; } // 日志级别
        public String Title { get; set; }   // 标题
        public String Message { get; set; } // 日志信息

        public LogData(LogLevel level, String title, String message)
        {
            this.Level = level;
            this.Title = title;
            this.Message = message;
        }

        public override String ToString()
        {
            StringBuilder buff = new StringBuilder();
            buff.Append("LogData - [").Append(Level).Append("] - ").Append(Title).Append(", ").Append(Message).Append(".");
            return buff.ToString();
        }
    }

    enum LogLevel
    {
        T,  // TRACE
        D,  // DEBUG
        I,  // INFO
        W,  // WARN
        E   // ERROR 
    }


    enum EntityType{
        FILE,       // 文件
        DIRECTORY   // 目录
    }

    enum EventType{
        //
        LOG_MESSAGE,
        //
        DATA_SYNC_ADD, // 数据同步-新增
        DATA_SYNC_UPD, // 数据同步-更新(包括新增和更新的)
        DATA_SYNC_DEL, // 数据同步-删除
        DATA_SYNC_REN  // 数据同步-重命名
    }

    enum EventState
    {
        UNKNOWN,
        READY,
        OPEN,
        PROCESSING,
        CLOSE
    }
}
